package com.czxy.enterprise.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.czxy.domain.TbCity;
import com.czxy.enterprise.service.CityService;
import com.czxy.findjob.vo.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 城市表 前端控制器
 * </p>
 *
 * @author xuewen
 * @since 2022-01-25
 */
@RestController
@RequestMapping("/city")
public class CityController {

    @Autowired
    private CityService cityService;
    @GetMapping
    public BaseResult findAllCity(){
        List<TbCity> list = cityService.findAllCity();
        return BaseResult.ok("查询成功!",list);
    }
    @GetMapping("/findCityByParentId/{id}")
    public BaseResult findCityById(@PathVariable("id") Integer id){
        List<TbCity> list = cityService.findCityById(id);
        return BaseResult.ok("查询成功!",list);
    }
    @GetMapping("/findAllCity")
    public BaseResult findAllCityChild(){
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.notIn("parent_id",new ArrayList<>().add("1"));
        return BaseResult.ok("查询成功",cityService.list(queryWrapper));
    }
    @GetMapping("/findByCityName")
    public BaseResult findByCityName(String cityName){
        cityName = cityName.replace("市","");
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("city_name",cityName);
        return BaseResult.ok("查询成功",cityService.getOne(queryWrapper));
    }
    @GetMapping("/findById/{id}")
    public BaseResult<TbCity> findById(@PathVariable("id") Integer id){
        TbCity tbCity = cityService.getById(id);
        return BaseResult.ok("查询成功",tbCity);
    }
}

